package com.starblink.share.view.utils

import com.starblink.android.basic.ext.encodeBase64
import com.starblink.android.basic.network.base.BaseApiClient.getCurrSvrCfgEnvH5Host

class ShareUrlUtils {

    // 话题详情页
    val tagPath = "tag?postId="
    val productPath = "product-detail?template=card"
    val picPath = "pic?postId="
    val videoPath = "video?postId="
    //测评详情
    val blogPath = "blog?postId="
    val whishlistPath = "wishlist"

    // 个人首页分享
    val personalHomeShare = "/user-invitation/homePage-share"

    // 达人介绍页
    val creatorsPath = "creators"

    // 达人指南
    val registerGuidancePath = "creators/register-guidance"

    // 达人合约
    val publisherTermsPath = "creators/publisher-terms"

    // 邀请达人规则
    val newCreatorRules = "creators/new-creator-invitation/rules"

    //达人明细规则
    val newCreatorBalance = "/creators/creator-portal/balance"

    //达人成长计划
    val CreatorGrowUpPlan = "/creators/growth-system"

    // ins导入
    val insImportpath = "creators/batch-import-guidance"

    // 达人注册
    val creatorsRegisterPath = "creators/register"

    // 用户注册
    val newUserRegisterPath = "creators/new-user-register"

    //心愿单
    val wishlistPath = "wishlist"

    //短信跳转app标识
    val turnappPath = "&tk=1"

    // 邀请新用户宣传页
    val creatorsUserInvitationPath = "creators/new-user-invitation"

    val pathMakeYourWishlist = "make-your-wishlist"

    // 邀请用户
    val inviteYourFriends = "/user-invitation/personal-invitation"


    fun getUrl(channel: ShareTypeEnum): String {
        val url: String = when (channel) {
            ShareTypeEnum.PIC_POST -> picPath
            ShareTypeEnum.VIDEO_POST -> videoPath
            ShareTypeEnum.TOPIC -> tagPath
            ShareTypeEnum.HASHTAG -> tagPath
            ShareTypeEnum.PRODUCT -> productPath
            ShareTypeEnum.PERSONAL_HOME_SHARE -> personalHomeShare
            ShareTypeEnum.WISHLIST_BOARDS_SHARE -> whishlistPath
        }
        return h5Url(url)
    }

    /**
     * 获取个人首页分享URL
     */
    fun getPersonalHomeShareUrl(userId: String): String {
        return "${getUrl(ShareTypeEnum.PERSONAL_HOME_SHARE)}?id=$userId"
    }

    /**
     * Wishlist-Boards-详情页分享
     */
    fun getWishlistBoardsDetailShareUrl(userId: String,wishListId:String?): String {
        return "${getUrl(ShareTypeEnum.WISHLIST_BOARDS_SHARE)}?ga=${wishListId?.encodeBase64()}&gb=${userId.encodeBase64()}"
    }

    private fun h5Url(h5SubUrl: String): String {
        var url = h5SubUrl
        while (url.startsWith("/")) {
            url = url.substring(1)
        }
        val cfgEnvUrl = getCurrSvrCfgEnvH5Host()
        return StringBuilder().append(cfgEnvUrl).append(url).toString()
    }
}